<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>开关灯</title>
</head>
<script src="./jquery-3.2.1.min.js"></script>

<body>
    <input type="button" value="关灯" id="btn" />
    <script>
        $(function() {
            $("#btn").click(function() {
                if ($(this).val() == "关灯") {
                    $("body").css("backgroundColor", "black");
                    $(this).val("开灯");
                } else {
                    $("body").css("backgroundColor", "white");
                    $(this).val("关灯");
                }
            });
        });
    </script>

</body>

</html>